﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.UI;
using System.Web.UI.WebControls;
using InfiniteGeek.Util;

namespace SampleWebApp
{
	public partial class Default : Page
	{
		public class Config : AutoConfig<Config> {
			static Config() { Init(); }

			[AutoConfigDefault(4096)]
			public static Int32 IndividualValue { get; private set; }

			[AutoConfigDefault(10000000)]
			public static Int32 ValueWithDefault { get; private set; }

			public static Int32 ValueWithNoDefault { get; private set; }

			public static String UpdateableValueWithNoDefault { get; set; }

			[AutoConfigIgnore]
			public static String ManuallyConfiguredProperty { get; set; }

			[AutoConfigSectionProperty("NVC")]
			public static NameValueCollection Values { get; private set; }

			[AutoConfigMultiValue]
			public static Int32[] Codes { get; private set; }

			public static String Override_Not { get; private set;}
			public static String Override_Default { get; private set; }
			public static String Override_Default_Config { get; private set; }
		
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			Config.ManuallyConfiguredProperty = "oneonezero";

			Repeater rptConfig = (Repeater)FindControl("rptConfig");
			Dictionary<string, object> configValues = new Dictionary<string,object>
				{
					{ "IndividualValue", Config.IndividualValue }, 
					{ "ManuallyConfiguredProperty", Config.ManuallyConfiguredProperty },
					{ "UpdateableValueWithNoDefault", Config.UpdateableValueWithNoDefault },
					{ "ValueWithDefault", Config.ValueWithDefault }, 
					{ "ValueWithNoDefault", Config.ValueWithNoDefault },
					{ "NVC.A", Config.Values[0] },
					{ "NVC.B", Config.Values["B"] },
					{ "Group/SectionA.Value1", GroupAConfig.Value1 },
					{ "Group/SectionB.Value1", GroupBConfig.Value1 },
					{ "codes", String.Join("|", Config.Codes) + " " + Config.Codes.GetType() },
					{ "SampleWebApp.Default.Config.Override_Not", Config.Override_Not},
					{ "SampleWebApp.Default.Config.Override_Default", Config.Override_Default},
					{ "SampleWebApp.Default.Config.Override_Default_Config", Config.Override_Default_Config}
				};

			rptConfig.DataSource = configValues;
			rptConfig.DataBind();
		}
	}
}